home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.8 KB | 142 lines | [TEXT/CWIE] |
- // PaneRowBase.cp
-
- #ifndef PaneRowBase_h
- #include "PaneRowBase.h"
- #endif
- #ifndef MinMax_h
- #include "MinMax.h"
- #endif
- #ifndef ArrangementLoop_h
- #include "ArrangementLoop.h"
- #endif
- #ifndef ConstArrangementLoop_h
- #include "ConstArrangementLoop.h"
- #endif
-
- void PaneRowBase::Arrange( Rectangle bounds )
- {
- uint16 minimum = MinimumWidth();
- uint16 width = bounds.Width();
-
- uint16 slop = ( width > minimum )
- ? width - minimum
- : 0;
-
- uint16 sloppySlop = ( slop > 0 )
- ? width - BestWidth( width )
- : 0;
-
- int16 leftSide = bounds.left;
-
- for ( ArrangementLoop pane( *this ); pane.Unfinished(); pane++ )
- {
- uint16 paneMinimum = (*pane)->MinimumWidth();
-
- uint16 paneWidth = ( slop > 0 )
- ? (*pane)->BestWidth( paneMinimum + slop )
- : Min( width, paneMinimum );
-
- if ( sloppySlop > 0 )
- {
- paneWidth += sloppySlop;
- sloppySlop = 0;
- }
-
- Assert( paneWidth <= width );
- width -= paneWidth;
- if ( paneWidth > paneMinimum )
- slop -= paneWidth - paneMinimum;
-
- Rectangle paneArea( leftSide,
- bounds.top,
- leftSide + paneWidth,
- bounds.bottom );
- Assert( bounds >= paneArea );
-
- pane->SetBounds( paneArea );
- leftSide = paneArea.right;
- }
- }
-
- uint16 PaneRowBase::MinimumWidth() const
- {
- return Total( &Sizeable::MinimumWidth );
- }
-
- uint16 PaneRowBase::MinimumHeight() const
- {
- return Maximum( &Sizeable::MinimumHeight );
- }
-
- uint16 PaneRowBase::MaximumWidth() const
- {
- return Total( &Sizeable::MaximumWidth );
- }
-
- uint16 PaneRowBase::MaximumHeight() const
- {
- return Minimum( &Sizeable::MaximumHeight );
- }
-
- uint16 PaneRowBase::ReasonableWidth() const
- {
- return Total( &Sizeable::ReasonableWidth );
- }
-
- uint16 PaneRowBase::ReasonableHeight() const
- {
- return Maximum( &Sizeable::ReasonableHeight );
- }
-
- uint16 PaneRowBase::BestWidth() const
- {
- return Total( &Sizeable::BestWidth );
- }
-
- uint16 PaneRowBase::BestWidth( uint16 bound ) const
- {
- uint16 minimum = MinimumWidth();
-
- if ( bound <= minimum )
- return bound;
-
- uint16 slop = bound - minimum;
-
- uint16 width = 0;
- for ( ConstArrangementLoop pane( *this ); pane.Unfinished(); pane++ )
- {
- uint16 paneMinimum = (*pane)->MinimumWidth();
- uint16 paneWidth = (*pane)->BestWidth( paneMinimum + slop );
-
- Assert( paneWidth >= paneMinimum );
-
- if ( !CanAdd( width, paneWidth ) )
- return maxuint16;
-
- width += paneWidth;
- slop -= paneWidth - paneMinimum;
- }
-
- Assert( width <= bound );
- return width;
- }
-
- uint16 PaneRowBase::BestHeight() const
- {
- return Maximum( &Sizeable::BestHeight );
- }
-
- uint16 PaneRowBase::BestHeight( uint16 bound ) const
- {
- uint16 best = 0;
-
- for ( ConstArrangementLoop pane( *this ); pane.Unfinished(); pane++ )
- {
- uint16 height = (*pane)->BestHeight( bound );
- if ( height > best )
- best = height;
- }
-
- return best;
- }
-